﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZhouYu.DreamTour.BLL.IService;
using ZhouYu.DreamTour.Model;
using ZhouYu.DreamTour.ViewModel;
using ZhouYu.DreamTour.Web.Models;

namespace ZhouYu.DreamTour.Web.Controllers
{
    public class OrderController : Controller
    {
        private IOrderService _orderService;

        public OrderController(IOrderService orderService)
        {
            _orderService = orderService;
        }

        /// <summary>
        /// 修改商品为到货状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult UpdateArrival(int id)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.Success = _orderService.UpdateArrival(id) > 0;
            return Json(responseResult, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 修改商品为已评价
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult Alreadyevaluated(int id)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.Success = _orderService.Alreadyevaluated(id) > 0;
            return Json(responseResult, JsonRequestBehavior.AllowGet);
        }


        /// <summary>
        /// 取消订单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>

        public JsonResult CancelSpecialty(int id)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.Success = _orderService.CancelSpecialty(id) > 0;
            return Json(responseResult, JsonRequestBehavior.AllowGet);
        }


        //添加商品评价
        public JsonResult AddCommodityevaluate(Usercomment usercomment)
        {
            ResponseResult responseResult = new ResponseResult();
            responseResult.Success = _orderService.AddCommodityevaluate(usercomment) > 0;
            return Json(responseResult, JsonRequestBehavior.AllowGet);

        }

        #region 添加订单信息
        /// <summary>
        /// 添加订单信息
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public JsonResult AddOrderInfo(OrderInfo orderInfo,int Id)
        {
            orderInfo.User_Id = UserInfoContext.userInfoContext.UserInfo.User_Id;
            ResponseResult responseResult = _orderService.AddOrderInfo(orderInfo, Id);
            return Json(responseResult);
        }
        #endregion


        #region 添加团购订单信息
        /// <summary>
        /// 添加订单信息
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public JsonResult AddGroupOrderInfo(OrderInfo orderInfo)
        {
            //用Session获取当前登录的用户Id给订单对象赋值
            orderInfo.User_Id = UserInfoContext.userInfoContext.UserInfo.User_Id;
            //调用添加团购订单方法
            ResponseResult responseResult = _orderService.AddGroupOrderInfo(orderInfo);
            return Json(responseResult);
        }
        #endregion

    }
}